import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["cardId"];

/**
 * 卡片管理
 * @date 2019-01-24
 */
import { CPAAS_PLATFORM } from 'utils/config';
import request from 'utils/request';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
/**
 * @typedef {object} Card - 卡片
 * @property {!string} code - 卡片编码
 * @property {!string} name -卡片名称
 * @property {string} description - 卡片描述
 * @property {!string} catalogType - 卡片类型
 * @property {!string} level - 层级
 * @property {1|2|3|4|5|6|7|8|9|10|11|12} w - 卡片宽度
 * @property {number} h - 卡片高度(1到200)
 * @property {boolean} [enabled=true] - 启用
 */

/**
 * @typedef {object} Tenant - 租户/集团
 * @property {!number} cardId - 卡片id
 * @property {number} id - 主键
 * @property {!number} tenantId - 租户id
 // * @property {string} tenantName - 租户名称
 // * @property {string} tenantNum - 租户编码
 */

function requestPreUrl() {
  return "".concat(CPAAS_PLATFORM, "/v1").concat(isTenantRoleLevel() ? "/".concat(getCurrentOrganizationId()) : '');
}
/**
 * 查询卡片信息
 * @param {object} params - 带分页信息的查询信息
 * @param {object} params.page - 分页信息
 * @param {object} params.sort - 排序信息
 * @param {string} params.code - 卡片编码
 * @param {string} params.name - 卡片名称
 * @param {string} params.fdLevel - 层级
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard/card
 * @requestUrl {CPAAS_PLATFORM}/v1/{organizationId}/dashboard/card
 * @requestMethod GET
 */


export function cardQueryPage(_x) {
  return _cardQueryPage.apply(this, arguments);
}
/**
 * 新建卡片
 * @param {Card} params
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard/card
 * @requestUrl {CPAAS_PLATFORM}/v1/{organizationId}/dashboard/card
 * @requestMethod POST
 */

function _cardQueryPage() {
  _cardQueryPage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var parseParams;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            parseParams = parseParameters(params);
            return _context.abrupt("return", request("".concat(requestPreUrl(), "/dashboard/card"), {
              method: 'GET',
              query: parseParams
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _cardQueryPage.apply(this, arguments);
}

export function cardInsert(_x2) {
  return _cardInsert.apply(this, arguments);
}
/**
 * 更新卡片
 * @param {Card} params
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard/card
 * @requestUrl {CPAAS_PLATFORM}/v1/{organizationId}/dashboard/card
 * @requestMethod PUT
 */

function _cardInsert() {
  _cardInsert = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(requestPreUrl(), "/dashboard/card"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _cardInsert.apply(this, arguments);
}

export function cardUpdate(_x3) {
  return _cardUpdate.apply(this, arguments);
}
/**
 * 获取卡片详情
 * @param {Card} params
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard/card/details/{dashboardCardId}
 * @requestUrl {CPAAS_PLATFORM}/v1/{organizationId}/dashboard/card/details/{dashboardCardId}
 * @requestMethod PUT
 */

function _cardUpdate() {
  _cardUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(requestPreUrl(), "/dashboard/card"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _cardUpdate.apply(this, arguments);
}

export function cardDetails(_x4) {
  return _cardDetails.apply(this, arguments);
}
/**
 * 查询卡片 已经分配的租户信息
 * @param {object} params - 带分页信息的查询信息
 * @param {object} params.page - 分页信息
 * @param {object} params.sort - 排序信息
 * @param {string} params.tenantName - 租户名称
 * @param {string} params.beginDate - 注册时间从
 * @param {string} params.endDate - 注册时间至
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard-tenant-cards/${cardId}
 * @requestUrl {CPAAS_PLATFORM}/v1/{organizationId}/dashboard-tenant-cards/${cardId}
 * @requestMethod GET
 */

function _cardDetails() {
  _cardDetails = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var dashboardCardId;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            dashboardCardId = params.dashboardCardId;
            return _context4.abrupt("return", request("".concat(requestPreUrl(), "/dashboard/card/details/").concat(dashboardCardId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _cardDetails.apply(this, arguments);
}

export function cardTenantQueryPage(_x5) {
  return _cardTenantQueryPage.apply(this, arguments);
}
/**
 * 给卡片 分配新的租户
 * @param {Tenant[]} params - 租户信息
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard-tenant-cards
 * @requestUrl {CPAAS_PLATFORM}/v1/{organizationId}/dashboard-tenant-cards
 * @requestMethod POST
 */

function _cardTenantQueryPage() {
  _cardTenantQueryPage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var cardId, restParams, parseParams;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            cardId = params.cardId, restParams = _objectWithoutProperties(params, _excluded);
            parseParams = parseParameters(restParams);
            return _context5.abrupt("return", request("".concat(requestPreUrl(), "/dashboard-tenant-cards/").concat(cardId), {
              method: 'GET',
              query: parseParams
            }));

          case 3:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _cardTenantQueryPage.apply(this, arguments);
}

export function cardTenantInsert(_x6) {
  return _cardTenantInsert.apply(this, arguments);
}
/**
 * 删除 卡片分配新的租户
 * @param {Tenant[]} params - 租户信息
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard-tenant-cards
 * @requestUrl {CPAAS_PLATFORM}/v1/{organizationId}/dashboard-tenant-cards
 * @requestMethod DELETE
 */

function _cardTenantInsert() {
  _cardTenantInsert = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(requestPreUrl(), "/dashboard-tenant-cards"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _cardTenantInsert.apply(this, arguments);
}

export function cardTenantDelete(_x7) {
  return _cardTenantDelete.apply(this, arguments);
}

function _cardTenantDelete() {
  _cardTenantDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(requestPreUrl(), "/dashboard-tenant-cards"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _cardTenantDelete.apply(this, arguments);
}